package com.southpark.demo.control.proxies.config
{
	import com.southpark.demo.control.proxies.BaseProxy;
	import com.southpark.demo.control.services.http.config.GetConfigSettingsHTTPService;
	import com.southpark.demo.vo.config.ConfigSettingsVO;
	import com.southpark.demo.vo.config.LanguageVO;
	import com.southpark.demo.vo.config.ThemeVO;
	import com.southpark.framework.control.responders.IResponder;
	
	import mx.collections.ArrayCollection;

	
	
	public class GetConfigSettingsProxy extends BaseProxy
	{
		
		public function GetConfigSettingsProxy(responder:IResponder)
		{
			super(responder,GetConfigSettingsHTTPService);
		}
		
		public function execute():void
		{			
			callService(this);
		}
		
		 
		override public function manageSuccess(data:Object):Object
		{
			var xml:XML = XML(data);
			
			isDebugMode = Boolean(int(xml.elements("isDebugMode")));
			isFakeServerMode = Boolean(int(xml.elements("isFakeServerMode")));
			
			var item:XML;
			var configSettings:ConfigSettingsVO = new ConfigSettingsVO();
			
			configSettings.configFileVersion = xml.attribute("version");
			
			configSettings.isDebugMode = Boolean(int(xml.elements("isDebugMode")));
			configSettings.isAutologinMode = Boolean(int(xml.elements("isAutologinMode")));
			configSettings.isUnitTestMode = Boolean(int(xml.elements("isUnitTestMode")));
			
			var language:LanguageVO;
			configSettings.languages = new ArrayCollection();
			for each (item in xml.elements("languages").elements("language"))
			{
				language = new LanguageVO;
				language.id = item.attribute("id");
				language.locale = item;
				configSettings.languages.addItem(language);
			};
			
			var theme:ThemeVO;
			configSettings.themes = new ArrayCollection();
			for each (item in xml.elements("themes").elements("theme"))
			{
				theme = new ThemeVO;
				theme.id = item.attribute("id");
				theme.source = item;
				configSettings.themes.addItem(theme);
			};
			
			var isContentStoreActive:Boolean = Boolean(int(xml.elements("contentStore").attribute("active")));
			if (isContentStoreActive)
			{
				configSettings.contentStoreURL = xml.elements("contentStore").elements("url");
			};
			
			return configSettings;
		}

	}
}